<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class imdb_api {

    public function get_movie_by_title($title, $language = "en-US") {
        //http://imdbapi.org/?title=evil+dead+2&type=json&plot=simple&episode=1&limit=1&yg=0&mt=none&lang=en-US&offset=&aka=simple&release=simple&business=0&tech=0
        $plot = "simple";   //none, simple, full
        $matched = preg_match('/(19|20)\d{2}\b/i', $title, $match);
        if (!$matched)
            return false;   // no matching if there's no year detected!
        $year = $match[0];
        $title_clean = trim(str_replace("({$year})", "", $title));
        $title_clean = urlencode($title_clean);
        $language = urlencode($language);
        $url = "http://imdbapi.org/?title={$title_clean}&year={$year}&type=json&plot={$plot}&episode=0&limit=3&yg=1&mt=none&lang={$language}&offset=&aka=simple&release=simple&business=0&tech=0";
        $content = file_get_contents($url);
        if (!$content)
            return false;
        $content_decoded = json_decode($content);
        return $content_decoded;
    }

}

?>
